﻿
@{
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" lay-filter="example">
                    <input type="hidden" name="id" value="@Model.id" />
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>
                            姓名
                        </label>
                        <div class="layui-input-inline">
                            <input style="height:38px;" disabled value="@Model.name" type="text" name="name" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>
                            邮件
                        </label>
                        <div class="layui-input-inline">
                            <input style="height:38px;" disabled value="@Model.email" type="text" name="email" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>
                            标题
                        </label>
                        <div class="layui-input-inline">
                            <input style="height:38px;" value="尊敬的@(Model.name),很荣幸收到您的留言" type="text" name="title" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="editor-area">
                        <div>
                            <script id="editor" type="text/plain">
                            </script>
                        </div>
                    </div>
                    @Html.AntiForgeryToken()
                    <div class="layui-form-item" style="margin-top:20px">
                        <button class="layui-btn layui-btn-lg" lay-filter="add" style="display:block;margin:auto" lay-submit="">
                            发送
                        </button>
                    </div>
                </form>
            </div>
        </div>
        <script type="text/javascript" charset="utf-8" src="~/ueditor/ueditor.config.js"></script>
        <script type="text/javascript" charset="utf-8" src="~/ueditor/ueditor.all.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="~/ueditor/lang/zh-cn/zh-cn.js"></script>
        <script>
            //实例化编辑器
        //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
            var ue = UE.getEditor('editor', {
                toolbars: [
                    ['fullscreen', 'source', 'undo', 'redo', 'bold', 'indent', 'italic', 'underline', 'strikethrough','time','date','fontsize','paragraph','link','justifyleft','justifyright','justifycenter','justifyjustify','forecolor','backcolor','charts']
            ],
            initialFrameWidth: 'auto',
            initialFrameHeight: 300,
            autoHeightEnabled: false,
            autoFloatEnabled:false

        });
        ue.ready(function () {
            ue.setContent(
                ` <p style="width: 600px;margin: auto;background-color: #f7f8fa;line-height: 100%;box-sizing: border-box;padding: 12px;">
			    <span style="display: block;border-top: 2px solid #0000FF;background-color: #FFF;">
				    <span style="font-size: 20px;font-weight: bold;display: block;padding:0px 10px;color: #323232;line-height: 28px;">尊敬的@(Model.name),您好！</span>
				    <span style="text-indent: 2em;font-size: 16px;display: block;padding:0 10px;color: #323232;line-height: 28px;">您提交的加盟信息我们已经收到，请确保您的联系电话与地址正确，我们的工作人员将与您进行下一步的沟通，感谢您的加入。</span>
 <span style="height: 10px;display: block;"></span>
                <span style="display: block;text-align: right;font-size: 14px;padding-right:20px;">XXX团队</span>
<span style="display: block;text-align: right;font-size: 12px;padding-right:20px;margin-top:10px">@DateTime.Now.ToString("yyyy/MM/dd")</span>
				    <span style="height: 10px;display: block;"></span>
                </span>
            </p>`
            )

        })
        layui.use(['form', 'layer','element','upload'],

            function() {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer,
                    upload = layui.upload;
                //监听提交
                form.on('submit(add)',
                    function (data) {
                        var index = layer.load(1);
                        var dataf = data.field;
                        dataf["content"] = dataf.editorValue
                    $.ajax({
                        url: '@Url.Action("Subform","Form",new { area="Admin"})',
                        data: dataf,
			            type: "post",
			            async:true,
			            dataType: 'json',
                        success: function (data) {
                            if (data.code == 200) {
                                //发异步，把数据提交给php
                                layer.alert(data.result, {
                                    icon: 6
                                },
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                            } else {
                                 layer.msg(data.result, { icon: 0, time: 2000 });
                            }
                        },
			            error:function(xhr,errorText,errorType){
                             alert("error");
                        },
			            complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
				            if(status=='timeout'){
					            ajax.abort();
					            alert("请求超时");
                            }
                            layer.close(index);
			            }
		            })

                    return false;
                });

            });
        </script>
    </body>
